import { useState, useEffect } from 'react';
import { searchMailList } from '@/services/mail';

// 模糊查询员工邮箱
const useSearchMailList = searchName => {
    const [resData, setResData] = useState([]);
    const [loading, setLoading] = useState(false);

    const fetchData = async () => {
        setLoading(true);
        const { data, code } = await searchMailList({ name: searchName });
        if (code === 10000) {
            setResData(data);
        }
        setLoading(false);
    };

    useEffect(() => {
        if (searchName) {
            fetchData();
        } else {
            setLoading(false); // 防抖loading问题
        }
    }, [searchName]);
    return [loading, resData, setResData, setLoading];
};

export default useSearchMailList;
